package wikiPhilia;

import processing.core.PApplet;
import processing.core.PVector;

public class WNode {
	public static final int TYPE_ARTICLE = 0;
	public static final int TYPE_PERSON = 1;
	public static final int TYPE_NON_PERSON = 2;
	public static final int TYPE_CATEGORY = 3;
	public static final int TYPE_UNDEF = 4;
	public static final int TYPE_PERSON_ZERO = 5;
	public static final int STATE_DEFAULT = 0;
	public static final int STATE_HIGHLIGHTED = 1;
	public static final int STATE_SELECTED = 2;
	private PApplet parent;
	private PVector pos;
	private PVector cPos; //= current position
	private PVector tPos; //= target position
	public static final float ACC = 0.05f;
	private String title;
	private int type;
	private int state = STATE_DEFAULT;
	private WArticle wItem;
	private int linksCount, backlinksCount, superCategoriesCount, subCategoriesCount;
	
	public WNode(PApplet parent, String title) {
		this.parent = parent;
		this.title = title;
		linksCount = 0;
		backlinksCount = 0;
		pos = new PVector();
		//pos = new PVector(parent.random(-2000,2000),parent.random(-2000,2000),parent.random(-2000,2000));
		tPos = pos;
		if (cPos == null) cPos = tPos;
	}
	public WNode(PApplet parent, String title, int type) {
		this.parent = parent;
		this.title = title; 
	    this.type = type;
		linksCount = 0;
		backlinksCount = 0;
		pos = new PVector();
		//pos = new PVector(parent.random(-2000,2000),parent.random(-2000,2000),parent.random(-2000,2000));
		tPos = pos;
		if (cPos == null) cPos = tPos;
	}

	public WNode(PApplet parent, WArticle wItem) {
		this.parent = parent;
		this.wItem = wItem;
		this.title = wItem.getTitle();
	}
	
	public void display() {
		parent.pushStyle();
		parent.strokeWeight(5*linksCount/(float)WikiPhilia_002.maxLinkCount+1f);			
		switch (type) {
		case TYPE_ARTICLE:
			parent.stroke(255,255,0,127);	
			switch (state) {
			case STATE_DEFAULT:
				break;
			case STATE_HIGHLIGHTED:
				parent.pushStyle();
				parent.pushMatrix();
				parent.noStroke();
				parent.fill(255);
				parent.translate(cPos.x, cPos.y,cPos.z);
				parent.rotateY(-WikiPhilia_006.yAngle);
				parent.rotateX(-WikiPhilia_006.xAngle);
				
				parent.text(title,0,0,0);
				parent.popMatrix();
				parent.popStyle();
				parent.strokeWeight(6f);
				break;
			case STATE_SELECTED:
				parent.stroke(255,255,0);	
				parent.strokeWeight(9f);
				break;

			default:
				break;
			}
			break;
		case TYPE_CATEGORY:
			parent.strokeWeight(5f);			
			parent.stroke(0,255,127,127);	

			break;
		case TYPE_PERSON_ZERO:
			//parent.strokeWeight(20f);			
			parent.stroke(255,0,0);	
			parent.pushStyle();
			parent.pushMatrix();
			parent.noStroke();
			parent.fill(255);
			parent.translate(cPos.x, cPos.y,cPos.z);
			parent.rotateY(-WikiPhilia_006.yAngle);
			parent.rotateX(-WikiPhilia_006.xAngle);
			parent.text(title,0,0,0);
			parent.popMatrix();
			parent.popStyle();

			break;

		default:
			break;
		}
		parent.beginShape(parent.POINT);
		parent.vertex(cPos.x,cPos.y,cPos.z);
		parent.endShape();
		parent.popStyle();
	}
	
	public void update () {
		cPos.x = (tPos.x-cPos.x)*ACC + cPos.x;
		cPos.y = (tPos.y-cPos.y)*ACC + cPos.y;
		cPos.z = (tPos.z-cPos.z)*ACC + cPos.z;
	}
	
	public void setPos(PVector pos) {
		this.pos = pos;
		tPos = pos;
	}
	public PVector getPos() {
		return cPos;
	}
	public void setParent(PApplet parent) {
		this.parent = parent;
	}
	public PApplet getParent() {
		return parent;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getTitle() {
		return title;
	}
	public void setType(int type) {
		this.type = type;
	}
	public int getType() {
		return type;
	}
	public void setwItem(WArticle wItem) {
		this.wItem = wItem;
	}
	public WArticle getwItem() {
		return wItem;
	}
	public void setBacklinksCount(int backlinksCount) {
		this.backlinksCount = backlinksCount;
	}
	public int getBacklinksCount() {
		return backlinksCount;
	}
	public void setLinksCount(int linksCount) {
		this.linksCount = linksCount;
	}
	public void incLinks() {
		linksCount++;
	}
	public void incBacklinks() {
		backlinksCount++;
	}
	public int getLinksCount() {
		return linksCount;
	}
	public void setSubCategoriesCount(int subCategoriesCount) {
		this.subCategoriesCount = subCategoriesCount;
	}
	public int getSubCategoriesCount() {
		return subCategoriesCount;
	}
	public void setSuperCategoriesCount(int superCategoriesCount) {
		this.superCategoriesCount = superCategoriesCount;
	}
	public int getSuperCategoriesCount() {
		return superCategoriesCount;
	}
	@Override
	public String toString() {
		return " " + title + ", linksCount= " + linksCount + ", backlinksCount= " + backlinksCount + "]" + "\n";
	}
	public PVector getcPos() {
		return cPos;
	}
	public void setcPos(PVector cPos) {
		this.cPos = cPos;
	}
	public PVector gettPos() {
		return tPos;
	}
	public void settPos(PVector tPos) {
		this.tPos = tPos;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	
}
